home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / cmprss.exe / TEST.CPP < prev    next >
C/C++ Source or Header  |  1993-01-26  |  2KB  |  132 lines

  1. #include <string.h>
  2. #include <iostream.h>
  3. #include "compress.cls"
  4. #include "decpress.cls"
  5.  
  6. main()
  7.     {
  8. cpofstream f1("test.out");
  9. ofstream fd("uncomp",ios::binary | ios::out);
  10. char str[20]="Hello world.\0";
  11.  
  12.     for (int j=0;j<127;j++)            // 127 so sign is not a problem
  13.         {
  14.         char c=j;
  15.         short s=j;
  16.         int i=j;
  17.         long l=j;
  18.         float f=j;
  19.         double d=j;
  20.         long double ld=j;
  21.  
  22.         f1<<c<<s<<i<<l<<f<<d<<ld;
  23.         f1.put(j);
  24.  
  25.         f1<<str;
  26.         f1<<&str;
  27.         f1.write(str,strlen(str)+1);
  28.         f1<<'a'<<str<<str<<'b'<<str<<'c';
  29.  
  30.         fd<<c<<s<<i<<l<<f<<d<<ld;
  31.         fd.put(j);
  32.  
  33.         fd<<str;
  34.         fd<<&str;
  35.         fd.write(str,strlen(str)+1);
  36.         fd<<'a'<<str<<str<<'b'<<str<<'c';
  37.  
  38.         }
  39.     fd.close();
  40.     f1.close();
  41.  
  42. cpifstream f2("test.out");
  43.  
  44.     for (j=0;j<127;j++)            // 127, so sign is not a problem
  45.         {
  46.         cout << j << '\n';
  47.         char c;
  48.         short s;
  49.         int i;
  50.         long l;
  51.         float f;
  52.         double d;
  53.         long double ld;
  54.  
  55.         f2>>c>>s>>i>>l>>f>>d>>ld;
  56.         if (c!=j)                    // verify all numbers OK
  57.             cout << "ERR1";
  58.         if (s!=j)
  59.             cout << "ERR2";
  60.         if (i!=j)
  61.             cout << "ERR3";
  62.         if (l!=j)
  63.             cout << "ERR4";
  64.         if (f!=j)
  65.             cout << "ERR5";
  66.         if (d!=j)
  67.             cout << "ERR6";
  68.         if (ld!=j)
  69.             cout << "ERR7";
  70.  
  71.         if (f2.get()!=j)
  72.             cout << "ERR8";
  73.  
  74.         memset(str,'q',13);
  75.         f2>>str;
  76.         if (strcmp(str,"Hello world."))
  77.             cout << "ERR9";
  78.  
  79.         if (j & 1)
  80.             {
  81.             f2.ignore(4,256);            // skip 4 bytes, don't check delimeter
  82.             }
  83.         else
  84.             {
  85.             long l;
  86.             f2>>l;
  87.             if (l!=(long)&str)
  88.                 cout << "ERR19";
  89.             }
  90.  
  91.         if (f2.peek()!='H')            // next char should be 'H'
  92.             cout << "ERR10";
  93.  
  94.         memset(str,'q',13);
  95.         f2.get(str,256,0);            // stop at \0
  96.         if (strcmp(str,"Hello world."))
  97.             cout << "ERR11";
  98.  
  99.         if (f2.get()!=0)            // pick up terminator
  100.             cout << "ERR12";
  101.  
  102.         f2.get(c);
  103.         if (c!='a')
  104.             cout << "ERR13";
  105.  
  106.         memset(str,'q',13);
  107.         f2.get(str,13,'Z');            // stop after 13 chars
  108.         if (strcmp(str,"Hello world."))
  109.             cout << "ERR14";
  110.  
  111.         memset(str,'q',13);
  112.         f2.getline(str,256,0);        // stop at delimeter and eat it
  113.         if (strcmp(str,"Hello world."))
  114.             cout << "ERR15";
  115.  
  116.         if (f2.get()!='b')
  117.             cout << "ERR16";
  118.  
  119.         memset(str,'q',13);            // stop after 13 bytes
  120.         f2.getline(str,13,0);
  121.         if (strcmp(str,"Hello world."))
  122.             cout << "ERR17";
  123.  
  124.         if (f2.get()!='c')
  125.             cout << "ERR18";
  126.         }
  127.     f2.close();
  128.  
  129.     return 0;
  130.     }
  131.  
  132.